package ticket8088.controller;


import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import ticket8088.entity.param.TicketAddParam;
import ticket8088.entity.vo.ResultVO;
import ticket8088.entity.vo.TicketVO;
import ticket8088.service.TicketService;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ttxxi
 * @since 2022-05-31
 */
@RestController
@RequestMapping("/ticket")
public class TicketController {
    @Resource
    TicketService ticketService;

    @ApiOperation("根据userId查询")
    @GetMapping
    public ResultVO<List<TicketVO>> getById(@RequestParam Long userId) {
        return new ResultVO.SUCCESS<>(ticketService.selectList(userId));
    }

    @ApiOperation("新增票据信息")
    @PostMapping
    public ResultVO add(@RequestBody TicketAddParam param) {
        Boolean res = ticketService.addTicket(param);
        if (res) {
            return new ResultVO.SUCCESS<>();
        } else {
            return new ResultVO.FAIL<>();
        }
    }

    @ApiOperation("删除")
    @DeleteMapping
    public ResultVO deleteTicket(Long id) {
        boolean res = ticketService.removeById(id);
        if (res) {
            return new ResultVO.SUCCESS<>();
        } else {
            return new ResultVO.FAIL<>();
        }
    }

}








